# Python 2.6.4
# Project Euler, Problem 82
# Copyright 2010 Talha Zaman

M = [[int(y) for y in x.strip().split(',')] for x in open("matrix.txt").readlines()]
N = [0]*len(M)
for i in range(1, len(M)):
    for j in range(0, len(M)):
        minadd = M[j][i-1]
        for k in range(0, j):
            path = M[k][i-1]
            for l in range(k, j):
                path += M[l][i]
            minadd = min(path, minadd)
        for k in range(len(M)-1, j, -1):
            path = M[k][i-1]
            for l in range(k, j, -1):
                path += M[l][i]
            minadd = min(path, minadd)
        N[j] = M[j][i] + minadd
    for j in range(len(M)):
        M[j][i] = N[j]
print min(M[i][len(M)-1] for i in range(len(M)))
